﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Baosight.ZNH.ZMCommon;
using Baosight.Platform.Core.UI.Controls;
using Baosight.Platform.Core;
using Baosight.ZNH.ZMCommon.ChildWindows;
using Baosight.Platform.Core.ServiceModel;
using Baosight.ZNH.ZMCommon.Prompt;
using Baosight.ZNH.ZP.UI.Utils;

namespace Baosight.ZNH.ZP.UI.PopWindows
{
    /// <summary>
    /// 增添资源
    /// </summary>
    /// Title:ResInsert
    /// Copyright:Baosight Software LTD.co Copyright (c) 2011
    /// Company:上海宝信软件股份有限公司
    /// Author: 梁琦
    /// Version: 1.0
    /// History:
    ///       2012-10-18  梁琦   [创建]
    ///  
    public partial class ResInsert : EFViewCmes
    {
        private TypeBlock typeBlock = new TypeBlock();

        public ResInsert(string dialogType)
        {
            InitializeComponent();
            base.BeforeAction += OnBeforeAction;
            Init(dialogType);
        }

        public override void Initialize(EIInfo initData)
        {
            initData.AddBlock(typeBlock.GetType());
            base.Initialize(initData);
        }
        /// <summary>
        /// 事前操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnBeforeAction(object sender, EventArgs e)
        {
            EFViewCmesProperty _view = new EFViewCmesProperty();
            _view.DataFields = this.ResQuery.GetChildObjects<EFDataField>(null, true);
            base.ViewProperty = _view;
        }

        /// <summary>
        /// 初始化页面数据
        /// </summary>
        private void Init(string type)
        {
            type = type == null ? "insert" : type.ToLower();
            if (type == "insert")
            {
                base.Mode = OperationMode.Insert;
            }
        }

        /// <summary>
        /// 确定按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CommitClick(object sender, RoutedEventArgs e)
        {
            TempButton = sender as Button;
            TempButton.IsEnabled = false;

            if (BeforeAction != null)
            {
                BeforeAction.Invoke(null, null);
            }



            EIInfo info = new EIInfo();
            info.Set(EIConstants.ServiceNameKey, eServiceName);
            info.Set(EIConstants.MethodNameKey, "insert");
            EIBlock block = info.AddBlock("ResResult");
            block.SetColumns(this.ResGrid.EIBlock.GetColumns());
            block.SetRows(this.ResGrid.CheckedEIRows);
            info.Set("Name", this.Name.Value);
            this.Submit(info, DoCommitCompleted);
        }


        /// <summary>
        /// 查询按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Query_Click(object sender, RoutedEventArgs e)
        {
            this.OnQueryButtonClick(sender, e);
        }
     



        /// <summary>
        /// 返回按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CancelClick(object sender, RoutedEventArgs e)
        {
            CmesWindows _window = this.Parent as CmesWindows;
            _window.DialogResult = false;
            _window.Close();
        }


        /// <summary>
        /// 消息提示
        /// </summary>
        public void ValidateMessagePopup(string msg)
        {
            Prompts pop = Prompts.getInstance();
            pop.SetMsg(msg);
            pop.Show(6);

            return;
        }
    }
}
